#include "Configuration.h"

std::map<string, string> Configuration::config = std::map<string, string>();

Configuration::Configuration(const char* file) {
	file_path = file;
}

bool Configuration::read_configuration() {
	file_cfg.open(file_path.c_str());

	if (file_cfg.is_open()) {
		string line;

		Log::log_oss << "Opening configuration file: '" << file_path << "'";
		Log::verbose();

		while (!file_cfg.eof()) {
			getline(file_cfg, line);
			int equals = line.find('=', 0);

			config.insert(std::pair<string, string>(line.substr(0, equals),
					line.substr(equals + 1)));
		}

		return true;
	}

	Log::error("Cannot open configuration file");
	return false;
}

string Configuration::get_property(string key) {
	std::map<string, string>::const_iterator it = config.find(key);

	if (it != config.end())
		return it->second;

	return "";
}
